package com.ruoyi.order.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.order.mapper.SysBrandMapper;
import com.ruoyi.order.domain.SysBrand;
import com.ruoyi.order.service.ISysBrandService;

/**
 * 品牌Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@Service
public class SysBrandServiceImpl implements ISysBrandService 
{
    @Autowired
    private SysBrandMapper sysBrandMapper;

    /**
     * 查询品牌
     * 
     * @param brandId 品牌主键
     * @return 品牌
     */
    @Override
    public SysBrand selectSysBrandByBrandId(Long brandId)
    {
        return sysBrandMapper.selectSysBrandByBrandId(brandId);
    }

    /**
     * 查询品牌列表
     * 
     * @param sysBrand 品牌
     * @return 品牌
     */
    @Override
    public List<SysBrand> selectSysBrandList(SysBrand sysBrand)
    {
        return sysBrandMapper.selectSysBrandList(sysBrand);
    }

    /**
     * 新增品牌
     * 
     * @param sysBrand 品牌
     * @return 结果
     */
    @Override
    public int insertSysBrand(SysBrand sysBrand)
    {
        sysBrand.setCreateTime(DateUtils.getNowDate());
        return sysBrandMapper.insertSysBrand(sysBrand);
    }

    /**
     * 修改品牌
     * 
     * @param sysBrand 品牌
     * @return 结果
     */
    @Override
    public int updateSysBrand(SysBrand sysBrand)
    {
        sysBrand.setUpdateTime(DateUtils.getNowDate());
        return sysBrandMapper.updateSysBrand(sysBrand);
    }

    /**
     * 批量删除品牌
     * 
     * @param brandIds 需要删除的品牌主键
     * @return 结果
     */
    @Override
    public int deleteSysBrandByBrandIds(Long[] brandIds)
    {
        return sysBrandMapper.deleteSysBrandByBrandIds(brandIds);
    }

    /**
     * 删除品牌信息
     * 
     * @param brandId 品牌主键
     * @return 结果
     */
    @Override
    public int deleteSysBrandByBrandId(Long brandId)
    {
        return sysBrandMapper.deleteSysBrandByBrandId(brandId);
    }


    @Override
    public TableDataInfo getBrandList(SysBrand sysBrand, Integer pageNum, Integer pageSize) {
        Page<SysBrand> page = new Page<>(pageNum, pageSize);

        Page<SysBrand> sysBrandPage = sysBrandMapper.selectPage(page, null);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(sysBrandPage.getRecords());
        rspData.setMsg("查询成功");
        rspData.setTotal(sysBrandPage.getTotal());
        return rspData;
    }

    @Override
    public AjaxResult getBrandListAll() {
        List<SysBrand> sysBrands = sysBrandMapper.selectSysBrandList(null);
        return AjaxResult.success(sysBrands);
    }
}
